(function($){
	var KEY = "jforest.extension";

	var Extension = function(element,options){
		this.el = element;
		this.options = $.extend({
			speed:1,
			right:0,
			extension:true
		},options);
		
		this.options.right = -$(this.el).innerWidth();
		if(this.options.extension == false){
			$(this.el).css('right',this.options.right);
		}else{
			$(this.el).css('right',0);
		}
        element.onmouseover = function () {
            startMove(1);
        };
        element.onmouseout = function () {
            startMove(0);
        }

	    var timer = null;
	    var self = this,opts = this.options;
	    function startMove(iTarget) {
	        clearInterval(timer);
	        timer = setInterval(function () {
	            if(iTarget){
	                element.style.right = parseFloat(element.style.right) + opts.speed + 'px';
	                if(parseFloat(element.style.right) >= 0){
	                    element.style.right = '0';
	                    window.clearInterval(timer);
	                }
	            }else {
	                element.style.right = parseFloat(element.style.right) - opts.speed + 'px';
	                if(parseFloat(element.style.right) <= opts.right){
	                	$(this.el).css('right',opts.right);
	                    window.clearInterval(timer);
	                }
	            }
	        }, 0);
	    }
	}

	$.fn.jfExtension = function(){
		var args = Array.prototype.slice.call(arguments, 0);
		var value = undefined;
		this.each(function () {
			var $this = $(this);
			if (args.length === 0 || typeof(args[0]) === "object") {
				opts = args.length === 0 ? {} : $.extend({}, args[0]);
				value = new Extension(this,opts);$this.data(KEY,value); //创建控件
			}else if (typeof(args[0]) === "string"){
				var entity = $this.data(KEY);
                if(entity === undefined){return;}
                value = entity[args[0]].apply(entity, args.slice(1));
			}else{
				 throw 'Invalid arguments to '+KEY+' plugin: ' + args;
			}
	    });
	    return (value === undefined) ? this : value;
	};
	
	$.fn.jfExtension.Constructor = Extension;
	
})(window.jQuery)